package com.example.mobile2021606177cke0407;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    private TextView tvMainTitle;
    private Button btnMainRes;
    private TextView tvMainQue1;
    private RadioGroup radGupMainLine1;
    private RadioButton radBtnMainRadbtn1A;
    private RadioButton radBtnMainRadbtn1B;
    private RadioButton radBtnMainRadbtn1C;
    private RadioButton radBtnMainRadbtn1D;
    private TextView tvMainQue2;
    private RadioGroup radGupMainLine2;
    private RadioButton radBtnMainRadbtn2A;
    private RadioButton radBtnMainRadbtn2B;
    private RadioButton radBtnMainRadbtn2C;
    private RadioButton radBtnMainRadbtn2D;
    private TextView tvMainQue3;
    private RadioGroup radGupMainLine3;
    private RadioButton radBtnMainRadbtn3A;
    private RadioButton radBtnMainRadbtn3B;
    private RadioButton radBtnMainRadbtn3C;
    private RadioButton radBtnMainRadbtn3D;
    private TextView tvMainQue4;
    private RadioGroup radGupMainLine4;
    private RadioButton radBtnMainRadbtn4A;
    private RadioButton radBtnMainRadbtn4B;
    private RadioButton radBtnMainRadbtn4C;
    private RadioButton radBtnMainRadbtn4D;
    private Button btnMainSub;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radGupMainLine1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupMainLine2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());

            }
        });
        radGupMainLine3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radGupMainLine4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = findViewById(checkedId);
                radioButton.getText().toString();
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int optionID1 = radGupMainLine1.getCheckedRadioButtonId();
                int optionID2 = radGupMainLine2.getCheckedRadioButtonId();
                int optionID3 = radGupMainLine3.getCheckedRadioButtonId();
                int optionID4 = radGupMainLine4.getCheckedRadioButtonId();
                if (optionID1 == R.id.radBtn_main_Radbtn1A & optionID2 == R.id.radBtn_main_Radbtn2B & optionID3 == R.id.radBtn_main_Radbtn3B & optionID4 == R.id.radBtn_main_Radbtn4C) {
                    btnMainSub.setText("分数：100分");
                } else if (optionID1 == R.id.radBtn_main_Radbtn1A & optionID2 == R.id.radBtn_main_Radbtn2C & optionID3 == R.id.radBtn_main_Radbtn3B || optionID2 == R.id.radBtn_main_Radbtn2C & optionID3 == R.id.radBtn_main_Radbtn3B & optionID4 == R.id.radBtn_main_Radbtn4A || optionID1 == R.id.radBtn_main_Radbtn1A & optionID3 == R.id.radBtn_main_Radbtn3B & optionID4 == R.id.radBtn_main_Radbtn4A) {
                    btnMainSub.setText("分数：75分");
                } else if (optionID1 == R.id.radBtn_main_Radbtn1A & optionID2 == R.id.radBtn_main_Radbtn2C || optionID1 == R.id.radBtn_main_Radbtn3B & optionID3 == R.id.tv_main_que3 || optionID1 == R.id.radBtn_main_Radbtn1A & optionID4 == R.id.radBtn_main_Radbtn4A || optionID2 == R.id.radBtn_main_Radbtn2C & optionID3 == R.id.radBtn_main_Radbtn3B || optionID2 == R.id.radBtn_main_Radbtn2C & optionID4 == R.id.radBtn_main_Radbtn4A || optionID3 == R.id.radBtn_main_Radbtn3B & optionID4 == R.id.radBtn_main_Radbtn4A) {
                    btnMainSub.setText("分数：50分");
                } else if (optionID1 == R.id.radBtn_main_Radbtn1A || optionID2 == R.id.radBtn_main_Radbtn2C || optionID3 == R.id.radBtn_main_Radbtn3B || optionID4 == R.id.radBtn_main_Radbtn4A) {
                    btnMainSub.setText("分数：25分");
                } else if (optionID1 == -1 || optionID2 == -1 || optionID3 == -1 || optionID4 == -1) {
                    Toast.makeText(MainActivity.this, "请作出选择", Toast.LENGTH_SHORT).show();
                } else {
                    btnMainSub.setText("分数：0分");
                }
            }
        });
        btnMainRes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radBtnMainRadbtn1A.setChecked(false);
                radBtnMainRadbtn1B.setChecked(false);
                radBtnMainRadbtn1C.setChecked(false);
                radBtnMainRadbtn1D.setChecked(false);
                radBtnMainRadbtn2A.setChecked(false);
                radBtnMainRadbtn2B.setChecked(false);
                radBtnMainRadbtn2C.setChecked(false);
                radBtnMainRadbtn2D.setChecked(false);
                radBtnMainRadbtn3A.setChecked(false);
                radBtnMainRadbtn3B.setChecked(false);
                radBtnMainRadbtn3C.setChecked(false);
                radBtnMainRadbtn3D.setChecked(false);
                radBtnMainRadbtn4A.setChecked(false);
                radBtnMainRadbtn4B.setChecked(false);
                radBtnMainRadbtn4C.setChecked(false);
                radBtnMainRadbtn4D.setChecked(false);
                btnMainSub.setText("");
                Toast.makeText(MainActivity.this, "重置完成", Toast.LENGTH_SHORT).show();


            }
        });

    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        btnMainRes = (Button) findViewById(R.id.btn_main_res);
        tvMainQue1 = (TextView) findViewById(R.id.tv_main_que1);
        radGupMainLine1 = (RadioGroup) findViewById(R.id.radGup_main_line1);
        radBtnMainRadbtn1A = (RadioButton) findViewById(R.id.radBtn_main_Radbtn1A);
        radBtnMainRadbtn1B = (RadioButton) findViewById(R.id.radBtn_main_Radbtn1B);
        radBtnMainRadbtn1C = (RadioButton) findViewById(R.id.radBtn_main_Radbtn1C);
        radBtnMainRadbtn1D = (RadioButton) findViewById(R.id.radBtn_main_Radbtn1D);
        tvMainQue2 = (TextView) findViewById(R.id.tv_main_que2);
        radGupMainLine2 = (RadioGroup) findViewById(R.id.radGup_main_line2);
        radBtnMainRadbtn2A = (RadioButton) findViewById(R.id.radBtn_main_Radbtn2A);
        radBtnMainRadbtn2B = (RadioButton) findViewById(R.id.radBtn_main_Radbtn2B);
        radBtnMainRadbtn2C = (RadioButton) findViewById(R.id.radBtn_main_Radbtn2C);
        radBtnMainRadbtn2D = (RadioButton) findViewById(R.id.radBtn_main_Radbtn2D);
        tvMainQue3 = (TextView) findViewById(R.id.tv_main_que3);
        radGupMainLine3 = (RadioGroup) findViewById(R.id.radGup_main_line3);
        radBtnMainRadbtn3A = (RadioButton) findViewById(R.id.radBtn_main_Radbtn3A);
        radBtnMainRadbtn3B = (RadioButton) findViewById(R.id.radBtn_main_Radbtn3B);
        radBtnMainRadbtn3C = (RadioButton) findViewById(R.id.radBtn_main_Radbtn3C);
        radBtnMainRadbtn3D = (RadioButton) findViewById(R.id.radBtn_main_Radbtn3D);
        tvMainQue4 = (TextView) findViewById(R.id.tv_main_que4);
        radGupMainLine4 = (RadioGroup) findViewById(R.id.radGup_main_line4);
        radBtnMainRadbtn4A = (RadioButton) findViewById(R.id.radBtn_main_Radbtn4A);
        radBtnMainRadbtn4B = (RadioButton) findViewById(R.id.radBtn_main_Radbtn4B);
        radBtnMainRadbtn4C = (RadioButton) findViewById(R.id.radBtn_main_Radbtn4C);
        radBtnMainRadbtn4D = (RadioButton) findViewById(R.id.radBtn_main_Radbtn4D);
        btnMainSub = (Button) findViewById(R.id.btn_main_sub);
    }
}


